<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="../../../common/taglibs.jsp"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<s:if
	test="@org.springside.modules.security.springsecurity.SpringSecurityUtils@getCurrentUserName() == 'anonymousUser'">
	<s:include value="/admin/login.jsp" />
</s:if>
<s:else>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>文件管理</title>
<style type="text/css">
/*data**********************************/
.main {
	height: 100%;
}

.data_more {
	float: right;
}

.data_more a {
	padding: 2px 0 0 15px;
	margin-right: 21px;
	cursor: pointer;
}

.data_more .upload {
	background: url(${ctx }/images/body_main_operate_selectall_p.png) 0 8px
		no-repeat;
}

.data_more .choice_all {
	background: url(${ctx }/images/body_main_operate_selectall_p.png) 0 8px
		no-repeat;
}
.data_more .choice_a{background: url(${ctx }/images/body_main_operate_selectall_p.png) 0 8px no-repeat;}
.data_more .delect {
	background: url(${ctx }/images/body_main_operate_delete_p.png) 0 8px
		no-repeat;
}

.data_more .add {
	background: url(${ctx }/images/body_main_operate_add_p.png) 0 8px
		no-repeat;
}

#users {
	border-collapse: collapse;
	width: 100%;
	border: 0 none;
	border-spacing: 0;
}

#users .title_bg {
	color: #010000;
	background-color: #e8e7e7;
	border-bottom: 1px solid #fff;
	font-size: 15px;
}

#users td {
	border-left: 1px solid #e2e2e2;
	padding: 5px;
	text-align: center;
}

#users .add_td {
	background: #eaeaea;
}

#users .table_content {
	
}

#users .name_part {
	display: none;
}

#users .notitle_change a {
	
}

#users .notitle_change input {
	border: 1px solid #ccc;
}

#users .yes,#users .no {
	display: inline-block;
	width: 16px;
	height: 10px;
	margin: 0 2px;
}

#users .yes {
	background: url(${ctx }/images/body_right_icon_p.png) no-repeat;
	background-position: 0 7px\9;
}

#users .no {
	background: url(${ctx }/images/body_false_icon_p.png) no-repeat;
	background-position: 0 7px\9;
}
object{
	float:right;
	background:#16aed8;
}
</style>
        <link href="${ctx }/css/public.css" rel="stylesheet" type="text/css" />
        <link href="${ctx }/uploadify-v2.1.0/uploadify.css" rel="stylesheet" type="text/css" />  
        <script type="text/javascript" src="${ctx }/uploadify-v2.1.0/jquery-1.3.2.min.js"></script>
        <script type="text/javascript" src="${ctx }/uploadify-v2.1.0/swfobject.js"></script>
        <script type="text/javascript" src="${ctx }/uploadify-v2.1.0/jquery.uploadify.v2.1.0.js"></script>
        <script type="text/javascript">
        $(document).ready(function() {
            $("#uploadify").uploadify({
                'uploader'       : '${ctx }/uploadify-v2.1.0/uploadify.swf', 
                'script'         : '${ctx }/admin/file-upload-admin!save.action',
                'cancelImg'      : '${ctx }/uploadify-v2.1.0/cancel.png',  
                'folder'         : 'upload',
                'queueID'        : 'fileQueue',
                'auto'           :  true,
                'multi'          :  false,
                'fileDataName'   : 'pictruepath', 
                'sizeLimit'      : 10*1024*1024,
                'buttonText'     : '文件上传',
                'onComplete' : function(event, queueID, fileObj, response, data) {  
                //$("#result").html(response);//显示上传成功结果  
                //setInterval("showResult()", 2000);//两秒后删除显示的上传成功结果  
                window.location.href="${ctx }/admin/file-upload-admin!list.action"//上传成功后跳转，并传递参数  
            }  
                 ,
                 onError          : function(event, queueID, fileObj){ 
                   alert("文件:" + fileObj.name + " 上传失败，文件应大于0K小于10M");}  
            });
        });
        </script>
</head>

<body>

	<div class="main">
		<div class="tip">
			<div id="fileQueue"></div>
           <input type="file" name="uploadify" id="uploadify"  />
			<span class="data_more">
			<a  class="choice_a" >全选</a>
			 <a class="choice_all">反选</a>
			 <a class="delect">删除</a>  </span>
			</span> <span>所在位置 :</span> <span class="current_position">资料管理</span>
		</div>
		<table id="users">
			<thead>
				<tr class="title_bg">
					<td width="3%"><a class="right-font08">序号</a></td>
					<td width="20%">文件名称</td>
					<td width="12%">上传时间</td>
					<td width="10%">操作</td>
				</tr>
			</thead>
			<s:iterator value="fileList" id="a">
				<tbody class="table_content" id="json_list">
					<tr class="control_list">
						<td class="notitle_border"><input type="checkbox"
							name="delid" id="${a.id}" class="checkbox" /></td>
						<td class="notitle_border notitle_change"><span
							class="name_this" id="${a.id}">${a.name}</span>
							<div class="name_part">
								<input type="text" maxlength="50" id="title"
								class="name_change" />

							</div></td>
						<td class="notitle_border">${a.editTime}</td>
						<td class="notitle_border"><span class="rename"
							style="cursor:pointer;">重命名</span>| <a
							href="${ctx }/admin/file-upload-admin!delete.action?id=${a.id}&type=u&currentpage=${pageNo}"
							onclick="return confirm('确定删除吗？')">删除</a></td>
					</tr>

				</tbody>
			</s:iterator>
		</table>
		<div class="page">
		  <div class="page_middle">
		
			<div class="page_lay">
				<a href="${ctx }/admin/file-upload-admin!list.action?currentpage=1">首页</a>
				<a
					href="${ctx }/admin/file-upload-admin!list.action?currentpage=${prePage}">上一页</a>
				第
				<s:property value="pageNo" />
				/${totalPages }页 <a
					href="${ctx }/admin/file-upload-admin!list.action?currentpage=${nextPage}">下一页</a>
				<a
					href="${ctx }/admin/file-upload-admin!list.action?currentpage=${totalPages }">尾页</a>
			</div>
			<input name="pages" id="pages" type="text" class="page_choice" /> 
			<input class="page_sure" type="button" onclick="go()" value=" ">
</div>
		</div>
	</div>
	<script type="text/javascript" src="${ctx }/js/public.js"></script>

	<script type="text/javascript">
		var xmlhttp;
		function loadXMLDoc(url, id, name, cfunc) {
			if (window.XMLHttpRequest) {
				// code for IE7+, Firefox, Chrome, Opera, Safari
				xmlhttp = new XMLHttpRequest();
			} else {
				// code for IE6, IE5
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}

			xmlhttp.onreadystatechange = cfunc;
			//用post上传
			 

			xmlhttp.open("post", url, false);
			xmlhttp.setRequestHeader("Content-type",
					"application/x-www-form-urlencoded");
			xmlhttp.send("name=" + name + "&id=" + id);
		}
		function myFunction1(id, name) {
			//console.log(id, name);
			//异步交互，，text.txt换成接口的名称
			loadXMLDoc("${ctx }/admin/file-upload-admin!rename.action", id,
					name, function() {
						if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
							
							var xmlDoc = xmlhttp.responseText;
							//xmldoc是返回的文本
						}
					});
		}
	</script>
	<script type="text/javascript">
		tool("data_more", "click");
		function go() {
			var pages = document.getElementById("pages").value;//得到id为pages输入框的值 
			if (pages > "${totalPages}") {
				pages = "${totalPages}";

			}
			if (pages < 1) {
				pages = 1;

			}
			location.href = "${ctx }/admin/file-upload-admin!list.action?currentpage="
					+ pages;
		}
		function tool(obj, evt) {
			//获取节点
			var obj = obj.nodeType ? obj : newdom.getElementsByClass(obj)[0];
			//console.log(obj.nodeType);
			switch (evt) {
			//鼠标点击事件
			case "click":
				obj.onclick = function(e) {
					//获取事件触发元素
					var _e = window.event ? window.event : e || arguments[0], target = _e.target ? _e.target
							: _e.srcElement, json_list = newdom.$("json_list"), control_list = newdom
							.getElementsByClass("control_list"), checkbox = newdom
							.getElementsByClass("checkbox"), len_checkbox = checkbox.length;
					//选择所有工具
					if (target.className == "choice_all") {
						for ( var i = 0; i < len_checkbox; i++) {
							if (checkbox[i].checked == true) {
								checkbox[i].checked = false;
							} else {
								checkbox[i].checked = true;
							}
						}

					}
					if(target.className == "choice_a"){
						for(var i = 0;i < len_checkbox;i++){
						
							checkbox[i].checked=true;
						}
						
					}
					//选择删除工具
					if (target.className == "delect") {

						var result = "";
						for ( var i = 0; i < len_checkbox; i++) {
							//如果被选中，删除所在行
							if (checkbox[i].checked == true && checkbox[i].id) {
								result += checkbox[i].id + ";";

							}
						}
						result = result.substring(0, result.length - 1);

						if (result == "") {
							alert("请选择要删除的记录");
						}

						else if (confirm('删除后的数据不可恢复，请慎重选择！\n确定要删除吗？')) {

							location.href = "${ctx }/admin/file-upload-admin!deleteByIds.action?ids="
									+ result + "&currentpage=${pageNo}";
						}

					}
				}
				break;
			//鼠标在元素上面
			case "mouse":
				//do something
				break;
			}
		}
	</script>
	<script type="text/javascript">
		//get node od dom
		var rename = newdom.getElementsByClass("rename"), name_part = newdom
				.getElementsByClass("name_part"), name_this = newdom
				.getElementsByClass("name_this"), name_change = newdom
				.getElementsByClass("name_change"),

		len_rename = rename.length;

		//for every rename ,add event click
		var ext = [];
		for ( var i = 0; i < len_rename; i++) {
			rename[i].index = i;
			// yes[i].index = i;
			// no[i].index = i;

			//点击重名民
			rename[i].onclick = function() {
				var that = this;
				var re = /\..+$/, re_1 = /^([-,_,\d,\w,\u3400-\u9FFF]+?(\s[-,_,\d,\w,\u3400-\u9FFF])*?)*$/;
				ext[this.index] = name_this[this.index].innerHTML.match(re);
				var rest = name_this[this.index].innerHTML.replace(re, "");
				name_this[this.index].style.display = "none";
				name_part[this.index].style.display = "block";
				name_change[this.index].value = rest;
				name_change[this.index].select();
				name_change[this.index].focus();

				//点击页面重命名框聚焦
				name_change[this.index].onblur = function(e) {
					var val = name_change[that.index].value;
					if (val == "") {
						content_alert("输入值不能为空");
					} else if (!re_1.test(val)) {
						content_alert("输入格式不正确,命名应由数字中午字母'——'或'_'组成");
					} else {
						
						name_this[that.index].innerHTML = name_change[that.index].value
								+ ext[that.index];
						name_this[that.index].style.display = "block";
						name_part[that.index].style.display = "none";
						myFunction1(name_this[that.index].id,
								name_this[that.index].innerHTML)
					}
					name_this[that.index].style.display = "block";
					name_part[that.index].style.display = "none";

				}

				// enter健确定
				document.onkeydown = function(e) {
					var _e = window.event ? window.event : e || arguments[0];
					if (_e.keyCode == 13) {
						name_change[that.index].blur();
					}

				}
			}
		}
 
		var title = document.getElementById("title");
    if(title){
      title.onkeyup = function(){
        if(title.value.length == 20){
          alert("标题字数不能大于20")
        }
      }
    }
		
	</script>
</body>
	</html>
</s:else>